package com.craftplay.dao;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.craftplay.model.Comment;

public class CommentSqlProvider {

    public String insertSelective(Comment record) {
        BEGIN();
        INSERT_INTO("comment");
        
        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=BIGINT}");
        }
        
        if (record.getFromId() != null) {
            VALUES("from_id", "#{fromId,jdbcType=INTEGER}");
        }
        
        if (record.getIsRoot() != null) {
            VALUES("is_root", "#{isRoot,jdbcType=INTEGER}");
        }
        
        if (record.getContent() != null) {
            VALUES("content", "#{content,jdbcType=VARCHAR}");
        }
        
        if (record.getParentId() != null) {
            VALUES("parent_id", "#{parentId,jdbcType=BIGINT}");
        }
        
        if (record.getToId() != null) {
            VALUES("to_id", "#{toId,jdbcType=INTEGER}");
        }
        
        if (record.getIsAttached() != null) {
            VALUES("is_attached", "#{isAttached,jdbcType=INTEGER}");
        }
        
        if (record.getCreatedTime() != null) {
            VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Comment record) {
        BEGIN();
        UPDATE("comment");
        
        if (record.getFromId() != null) {
            SET("from_id = #{fromId,jdbcType=INTEGER}");
        }
        
        if (record.getIsRoot() != null) {
            SET("is_root = #{isRoot,jdbcType=INTEGER}");
        }
        
        if (record.getContent() != null) {
            SET("content = #{content,jdbcType=VARCHAR}");
        }
        
        if (record.getParentId() != null) {
            SET("parent_id = #{parentId,jdbcType=BIGINT}");
        }
        
        if (record.getToId() != null) {
            SET("to_id = #{toId,jdbcType=INTEGER}");
        }
        
        if (record.getIsAttached() != null) {
            SET("is_attached = #{isAttached,jdbcType=INTEGER}");
        }
        
        if (record.getCreatedTime() != null) {
            SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }
}